package 扎金花;

import java.util.Scanner;

public class 扎金花 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String s1 = sc.next();
			String s2 = sc.next();
			System.out.println(compare(s1, s2));
		}
		sc.close();
	}

	public static int compare(String s1, String s2) {
		if (check(s1) == false || check(s2) == false)
			return -2;

		int[] a1 = str2arr(s1);
		int[] a2 = str2arr(s2);
		String p1 = getPatterns(s1);
		String p2 = getPatterns(s2);

		if (a1[0] == a2[0] && a1[1] == a2[1] && a1[2] == a2[2])
			return 0;

		if ((p1.equals("baozi") || p1.equals("duizi") || p1.equals("shunzi")) && (p2.equals("none")))
			return 1;
		if ((p2.equals("baozi") || p2.equals("duizi") || p2.equals("shunzi")) && (p1.equals("none")))
			return -1;

		if ((p1.equals("none")) && (p2.equals("none"))) {
			if (a1[0] > a2[0])
				return 1;
			if (a1[0] < a2[0])
				return -1;
			if (a1[0] == a2[0] && a1[1] > a2[1])
				return 1;
			if (a1[0] == a2[0] && a1[1] < a2[1])
				return -1;
			if (a1[0] == a2[0] && a1[1] == a2[1] && a1[2] > a2[2])
				return 1;
			if (a1[0] == a2[0] && a1[1] == a2[1] && a1[2] < a2[2])
				return -1;
		}

		if ((!p1.equals("none")) && (!p2.equals("none"))) {
			if (p1.equals("baozi") && !p2.equals("baozi"))
				return 1;
			if (p2.equals("baozi") && !p1.equals("baozi"))
				return -1;
			if (p1.equals("shunzi") && p2.equals("duizi"))
				return 1;
			if (p2.equals("shunzi") && p1.equals("duizi"))
				return -1;

			if (p1.equals("baozi") && p2.equals("baozi") && a1[0] > a2[0])
				return 1;
			if (p1.equals("baozi") && p2.equals("baozi") && a1[0] < a2[0])
				return -1;
			if (p1.equals("shunzi") && p2.equals("shunzi") && a1[0] > a2[0])
				return 1;
			if (p1.equals("shunzi") && p2.equals("shunzi") && a1[0] < a2[0])
				return -1;
			if (p1.equals("duizi") && p2.equals("duizi") && a1[2] > a2[2])
				return 1;
			if (p1.equals("duizi") && p2.equals("duizi") && a1[2] < a2[2])
				return -1;
		}

		return -1;
	}

	public static String getPatterns(String s) {
		int[] a = str2arr(s);
		if (a[0] == a[1] && a[2] == a[1] && a[0] == a[2]) {
			return "baozi";
		} else if (a[0] == a[1] || a[2] == a[1] || a[0] == a[2]) {
			return "duizi";
		} else if (a[0] - 1 == a[1] && a[1] - 1 == a[2]) {
			return "shunzi";
		}
		return "none";
	}

	public static int[] str2arr(String s) {
		int[] a = new int[3];
		char[] c = s.replaceAll("0", "").toCharArray();
		for (int i = 0; i < c.length; i++) {
			switch (c[i]) {
			case '2':
				a[i] = 2;
				break;
			case '3':
				a[i] = 3;
				break;
			case '4':
				a[i] = 4;
				break;
			case '5':
				a[i] = 5;
				break;
			case '6':
				a[i] = 6;
				break;
			case '7':
				a[i] = 7;
				break;
			case '8':
				a[i] = 8;
				break;
			case '9':
				a[i] = 9;
				break;
			case '1':
				a[i] = 10;
				break;
			case 'J':
				a[i] = 11;
				break;
			case 'Q':
				a[i] = 12;
				break;
			case 'K':
				a[i] = 13;
				break;
			case 'A':
				a[i] = 14;
				break;
			default:
				break;
			}
		}

		for (int i = 0; i < a.length; i++) {
			for (int j = i + 1; j < a.length; j++) {
				if (a[i] < a[j]) {
					a[i] = a[i] ^ a[j];
					a[j] = a[i] ^ a[j];
					a[i] = a[i] ^ a[j];
				}
			}
		}
		return a;
	}

	public static boolean check(String s) {
		// 长度
		if (s.length() < 3 || s.length() > 6) {
			return false;
		}

		String tmp = s.replaceAll("0", "");
		if (tmp.length() != 3) {
			return false;
		}

		// 字符
		for (int i = 0; i < s.length(); i++) {
			if (!"2,3,4,5,6,7,8,9,10,J,Q,K,A".contains(String.valueOf(s.charAt(i)))) {
				return false;
			}
		}
		// 10检测
		if (s.length() == 3 && s.contains("0")) {
			return false;
		} else if (s.length() == 4 && (!s.contains("10"))) {
			return false;
		} else if (s.length() == 5) {
			int cnt0 = 0, cnt1 = 0;
			for (int i = 0; i < s.length(); i++) {
				if (s.charAt(i) == '0')
					cnt0++;
				if (s.charAt(i) == '1')
					cnt1++;
			}
			if (cnt0 != 2 || cnt1 != 2) {
				return false;
			}
			//
			if ((s.charAt(2) != '1' && s.charAt(2) != '0')
					&& (s.charAt(0) != '1' || s.charAt(1) != '0' || s.charAt(3) != '1' || s.charAt(4) != '0')) {
				return false;
			}
			//
			if ((s.charAt(0) != '0' && s.charAt(0) != '1') && !s.contains("1010")) {
				return false;
			}
			if ((s.charAt(4) != '0' && s.charAt(4) != '1') && !s.contains("1010")) {
				return false;
			}

		} else if (s.length() == 6 && (!s.equals("101010"))) {
			return false;
		}
		return true;
	}
}
